import 'package:flutter/material.dart';
import 'package:ls_work/a_yyt/page/Take_leave_page.dart';
import 'package:ls_work/res/colors.dart';
// import 'package:ls_work/widgets/search_bar.dart';

class TakeLeaveHomePage extends StatefulWidget {
  // final ElderInfo info;
  // TakeLeaveHomePage({Key key,this.info});
  @override
  _TakeLeaveHomePageState createState() => _TakeLeaveHomePageState();
}

class _TakeLeaveHomePageState extends State<TakeLeaveHomePage>
    with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  TabController? _tabController;
  PageController _pageController = PageController(initialPage: 0);

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
    _tabController = new TabController(vsync: this, length: 2);
  }

  @override
  void dispose() {
    _tabController?.dispose();
    super.dispose();
  }

  _onPageChange(int index) {
    _tabController?.animateTo(index);
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: AppBar(
        elevation: 0.5,
        title: TabBar(
          onTap: (index) {
            if (!mounted) {
              return;
            }
            _pageController.jumpToPage(index);
          },
          isScrollable: false,
          controller: _tabController,
          labelStyle: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
          unselectedLabelStyle:
              TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
          indicatorSize: TabBarIndicatorSize.label,
          unselectedLabelColor: Colours.text_normal,
          labelColor: Colors.black,
          indicatorColor: Colours.app_main,
          indicatorWeight: 5,
          tabs: <Widget>[
            Tab(text: '已离院'),
            Tab(text: '已返院'),
          ],
        ),
        // bottom: SearchBar(
        //   hintText: "请输入长者姓名查询",
        //   isShowBackButton: false,
        //   onPressed: (text) {
        //     FocusScope.of(context).unfocus();
        //     // _keyword = text;
        //     // _onRefresh();
        //   },
        // ),
      ),
      body: PageView.builder(
        key: const Key('pageView'),
        itemCount: 2,
        onPageChanged: _onPageChange,
        controller: _pageController,
        itemBuilder: (BuildContext context, int index) {
          switch (index) {
            case 0:
              return TakeLeavePage(leaveType: 1);
              break;
            case 1:
              return TakeLeavePage(leaveType: 2);
              break;
            default:
              return Container();
          }
        },
      ),
    );
  }
}
